<?php
namespace app\club\controller\recharge;

use app\common\controller\Clubend;
use fast\Http;
use think\Config;
use think\Session;

//个人自定义配置文件在extra backstage中;
class Api extends Clubend
{   

    protected $goodsconfig = [];
    public function _initialize($options = [])
    {   
		//获取配置文件
		$this->GameDBConfig = Config::get('GameDB'); 		// 获取游戏服务器的IP地址等信息
		$this->DatabaseConfig = Config::get('database'); 	//获取数据库连接.
		
        /**
         * 跨域设置
         */
        header("Access-Control-Allow-Origin: *"); // 允许任意域名发起的跨域请求 
        header('Access-Control-Allow-Methods:PUT,POST,GET,DELETE,OPTIONS');
        header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With'); 
    }
    
    /**
     * 从代理后台自动登录俱乐部
     * @author violet
     */
    public function login(){
        $url = Config::get('GameDB.http').$this->request->get('url', '/club/index/index');
        if (Session::get('owner'))
        {
            return callback(true,'已经登录过',$url);
        }
        if (!$this->request->isPost())
        {
            return callback(false,'请正确的进入俱乐部');
        }
        $LoginName = $this->request->post('LoginName');
        $Password = $this->request->post('Password');
        if(empty($LoginName) || empty($Password)){
            return callback(false,'登录名及密码不能为空');
        }
        $where['LoginName'] = $LoginName;
        $owner = $this->selectTbaleInfo($this->DatabaseConfig,'fa_y_agency',$where);//获取数据库订单
        if (empty($owner))
        {
            return callback(false,'登录名不存在');
        }
        if ($owner['Password'] != strtoupper(md5($Password)))
        {
            return callback(false,'密码不正确');
        }
        Session::set("owner", $owner);
        return callback(true,'登录成功',$url);
    }
    
    

}